<template>
    <div class="minishop-home ">
        <index v-if="active==0"></index>
        <discover v-if="active==1"></discover>
        <order v-if="active==2"></order>
        <personal v-if="active==3"></personal>

        <NavBar v-if="active!=-1" :activeSrc="active" name="index3" ></NavBar>
    </div>
</template>

<script>
import index from "./index";
import discover from "./discover";
import personal from "@/pages/personal/index";
import order from "@/pages/personal/order/index";
export default {
    data () {
        return {
            active: -1
        }
    },
    watch: {
        '$store.getters.menuActive': {
            handler(n, o){
                this.active = n
            }
        },
    },
    components: {
        index,
        order,
        discover,
        personal
    },
    onLoad(options){
        if(options.active!=undefined){
            this.active = parseInt(options.active)
        } else {
            this.active = 0
        }
    },
    mounted () {
        // this.initPage()
    },
    onShow(){
        
    },
    methods: {
        activeMenu(active){
            this.active = active
        },
        initPage(){
            this.ListTip()
            this.ListPlace()
            this.ListBanner()
            this.ListHouse()
        },
        ListTip(){
            tipApi.ListTip({
                pageIndex: 1,
                pageSize: 6
            }).then(data => {
                this.tipList = data.result.List || []
            })
        },
        ListPlace(){
            placeApi.ListPlace({
                pageIndex: 1,
                pageSize: 6
            }).then(data => {
                data.result.List.forEach(v => {
                    v.tags = (v.tag&&v.tag.split(" ")) || []
                })
                this.placeList = data.result.List || []
            })
        },
        ListHouse(){
            houseApi.ListHouse({
                pageIndex: 1,
                pageSize: 3
            }).then(data => {
                this.houseList = data.result.List || []
            })
        },
        ListBanner(){
            otherApi.ListBanner({
                adTypes: [1, 2]
            }).then(data => {
                // var barnerList = [];
                // (data.result||[]).forEach(v => {
                //     if(v.ad_type == 1){
                //         barnerList.push(v)
                //     } else if(v.ad_type == 4 && !this.advice){
                //         this.advice = v
                //     }
                // })
                
                this.barnerList = data.result
            })
        },
    },
    onShareAppMessage( options ){
        var that = this;
        // 设置菜单中的转发按钮触发转发事件时的转发内容
        var shareObj = {
            title: "",// 默认是小程序的名称(可以写slogan等)
            path: '/pages/index/index',// 默认是当前页面，必须是以‘/’开头的完整路径
            imageUrl: "",//自定义图片路径，可以是本地文件路径、代码包文件路径或者网络图片路径，支持PNG及JPG，不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
            success: function(res){
                // 转发成功之后的回调
                if(res.errMsg == 'shareAppMessage:ok'){
                    wx.showToast({
                        title: "分享成功",
                        icon: "success",
                        duration: 2000
                    })
                }
            },
            fail: function() {
                // 转发失败之后的回调
                if(res.errMsg == 'shareAppMessage:fail cancel'){
                    // 用户取消转发
                
                }else if(res.errMsg == 'shareAppMessage:fail'){
                    // 转发失败，其中 detail message 为详细失败信息
                    wx.showToast({
                        title: "分享失败",
                        icon: "success",
                        duration: 2000
                    })
                }
            },
            complete: function () {
                
            }
        };
        // 来自页面内的按钮的转发
        if( options.from == 'button' ){
            　
        }
        // 返回shareObj
        return shareObj;
    },
}
</script>

<style  lang="scss">
</style>
